﻿using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;

namespace JQueryPractice.controls
{
    public delegate void Filter();

    public class FilterGroup : CompositeControl
    {
        private readonly Dictionary<string, EventHandler> filters = new Dictionary<string, EventHandler>();

        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            foreach (KeyValuePair<string, EventHandler> filter in filters)
            {
                SwitchButton button = new SwitchButton { Text = filter.Key };
                button.Click += filter.Value;
                Controls.Add(button);
            }
            ChildControlsCreated = true;
        }


        public void AddFilter(string value,Filter filter)
        {
            filters.Add(value, delegate { filter(); });
        }

    }
}
